package com.jingdianjichi.auth.domain.service.impl;

import com.jingdianjichi.auth.common.enums.IsDeleteEnum;
import com.jingdianjichi.auth.domain.entity.AuthPermissionBO;
import com.jingdianjichi.auth.domain.entity.AuthRolePermissionBO;
import com.jingdianjichi.auth.domain.service.AuthRolePermissionDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRolePermission;
import com.jingdianjichi.auth.infra.basic.service.impl.AuthRolePermissionServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Resource
    private AuthRolePermissionServiceImpl authRolePermissionServiceImpl;
    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        //批量插入角色权限列表
        List<AuthRolePermission> authRolePermissionList=new ArrayList<>();
        Long roleId=authRolePermissionBO.getRoleId();
        authRolePermissionBO.getPermissionIdList().forEach(permissionId->{
            AuthRolePermission authRolePermission=new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeleteEnum.UN_DELETED.getCode());
            authRolePermissionList.add(authRolePermission);
        });
        return authRolePermissionServiceImpl.insertBatch(authRolePermissionList)>0;
    }

}
